namespace MetaView.Core;

/// <summary>
/// 可等待的路由包。
/// </summary>
public class WaitRouterPackage : MsgRouterPackage, IWaitResult
{
    /// <inheritdoc/>
    public int Sign { get; set; }

    /// <inheritdoc/>
    public byte Status { get; set; }

    /// <summary>
    /// 是否将<see cref="Sign"/>和<see cref="Status"/>等参数放置在Router中。
    /// </summary>
    protected virtual bool IncludedRouter { get; }

    /// <inheritdoc/>
    public override void PackageBody<TByteBlock>(ref TByteBlock byteBlock)
    {
        base.PackageBody(ref byteBlock);
        if (this.IncludedRouter)
        {
            return;
        }

        byteBlock.WriteInt32(this.Sign);
        byteBlock.WriteByte(this.Status);
    }

    /// <inheritdoc/>
    public override void PackageRouter<TByteBlock>(ref TByteBlock byteBlock)
    {
        base.PackageRouter(ref byteBlock);
        if (!this.IncludedRouter)
        {
            return;
        }

        byteBlock.WriteInt32(this.Sign);
        byteBlock.WriteByte(this.Status);
    }

    /// <inheritdoc/>
    public override void UnpackageBody<TByteBlock>(ref TByteBlock byteBlock)
    {
        base.UnpackageBody(ref byteBlock);
        if (!this.IncludedRouter)
        {
            this.Sign = byteBlock.ReadInt32();
            this.Status = byteBlock.ReadByte();
        }
    }

    /// <inheritdoc/>
    public override void UnpackageRouter<TByteBlock>(ref TByteBlock byteBlock)
    {
        base.UnpackageRouter(ref byteBlock);
        if (this.IncludedRouter)
        {
            this.Sign = byteBlock.ReadInt32();
            this.Status = byteBlock.ReadByte();
        }
    }
}